package com.frinder.hadoop.job.joiner;

import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.StringTokenizer;

/**
 * @author frinder
 * @date 2018/6/26
 * @Description: 读取 DeptName.txt
 */
@Slf4j
public class DeptNameMapper extends Mapper<LongWritable, Text, TextPair, Text> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        log.info("Text:{}", value);
        StringTokenizer tokenizer = new StringTokenizer(String.valueOf(value), "\t");
        String deptID = tokenizer.nextToken();
        log.info("deptID:{}", deptID);
        String name = null;
        if (tokenizer.hasMoreTokens()) {
            name = tokenizer.nextToken();
        }
        context.write(new TextPair(deptID, "1"), new Text(name));
    }
}
